// pages/conference/input_third.js
import {this_year,next_year,my_request,my_showToast_error,my_showToast_ok,gen_query_str} from '../../utils/my_utils'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    detail_url:"/pages/conference/process_input",
    preview_url:"/pages/ActivityDetail/index",
    back_url:"/pages/conference/input_second",
    conference_process:[],
  },
  new_process:function(){
    this.change_step(this.data.detail_url)
  },
  go_to_preview:function(){
    var query_data={...this.data.query_data};
    var jump_url=this.data.preview_url+gen_query_str(query_data);
    wx.navigateTo({
      url:jump_url
    })
  },
  go_back:function(){
    this.change_step(this.data.back_url)
  },
  save_props:function(options){
    var query_data={...options};
    query_data.back="cache"
    this.setData({
      query_data:query_data
    })
  },
  add_props:function(key,value){
    var query_data = {...this.data.query_data};
    query_data[key]=value;
    this.setData({
      query_data:query_data
    });
  },
  change_step:function(go_url){
    var query_data={...this.data.query_data};
    var jump_url=go_url+gen_query_str(query_data);
    console.log("third_step:"+jump_url);
    wx.redirectTo({
      url:jump_url
    })
  },
  add_process:function(e){
    //var process_id=e.currentTarget.dataset.id;
    var query_data={...this.data.query_data};
    //query_data.process_id=process_id
    query_data.type="new"
    var jump_url = this.data.detail_url+gen_query_str(query_data);
    wx.navigateTo({
      url:jump_url
    })
  },
  change_process:function(e){
    var process_id=e.currentTarget.dataset.process_id;
    var query_data={...this.data.query_data};
    query_data.process_id=process_id;
    query_data.time=encodeURI(e.currentTarget.dataset.time);
    query_data.content=encodeURI(e.currentTarget.dataset.content);
    var jump_url = this.data.detail_url+gen_query_str(query_data);
    wx.navigateTo({
      url:jump_url
    })
  },
  delete_from_server:function(e){
    var that=this;
    var post_data={
      meeting:+this.data.query_data.edit_id,
      publisher:+this.data.query_data.publisher,
      process_id:+e.currentTarget.dataset.process_id
    }
    my_request({
      url: 'https://sichuangyi.demopp.in/api-conference-alpha/detail/remove',
      method: "POST",
      data: post_data,
      success:function(res){
        my_showToast_ok("删除成功",2000)
        that.load_process()
      },
      fail: function() {
        my_showToast_error("删除失败",2000)
      }
    })
  },
  load_process:function(){
    var edit_id = +this.data.query_data.edit_id;
    var that=this;
    my_request({
      url: 'https://sichuangyi.demopp.in/api-conference-alpha/conference-process',
      method: "GET",
      data: {
        meeting_id: edit_id
      },
      success: function (res) {
        var infoArr = res.data.data.process;
        //console.log(infoArr);
        that.setData({
          conference_process: infoArr,
        })
      },
      fail: function (res) {
        my_showToast_error("会议加载失败，请一会刷新",2000)
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.save_props(options)
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.load_process()
  }
})